package com.mk.admin.service.impl;

import com.mk.admin.mapper.QuestionTypeMapper;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.entity.QuestionTypeEntity;
import com.mk.admin.model.vo.QuestionTypeVo;
import com.mk.admin.service.QuestionTypeService;
import com.mk.admin.util.JSONCopy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QuestionTypeServiceImpl implements QuestionTypeService {
    @Autowired
    private QuestionTypeMapper questionTypeMapper;

    @Override
    public ResultDto select(QuestionTypeVo questionTypeVo) {
        QuestionTypeEntity entity = JSONCopy.copy(questionTypeVo, QuestionTypeEntity.class);
        return ResultDto.data(questionTypeMapper.count(entity), questionTypeMapper.select(entity));
    }

    @Override
    public ResultDto add(QuestionTypeVo questionTypeVo) {
        QuestionTypeEntity entity = JSONCopy.copy(questionTypeVo, QuestionTypeEntity.class);

        return ResultDto.data(questionTypeMapper.insert(entity));
    }

    @Override
    public ResultDto update(QuestionTypeVo questionTypeVo) {
        QuestionTypeEntity entity = JSONCopy.copy(questionTypeVo, QuestionTypeEntity.class);
        return ResultDto.data(questionTypeMapper.updateById(entity));
    }

    @Override
    public ResultDto delete(int id) {
        return ResultDto.data(questionTypeMapper.deleteById(id));
    }

    @Override
    public ResultDto status(int id) {
        return ResultDto.data(questionTypeMapper.status(id));
    }
}
